<template>
  <div class="app-container">
    <div class="content-management">
      <div slot="header" class="clearfix">
        <ComSelect :options="options" @EventChange="changeFn"></ComSelect>
      </div>
      <div class="text item">
        <!-- <ComForm :modes="formModes" :list="listForm"></ComForm> -->
      </div>
      <div class="conform" style="margin-top: 20px">
        <comForm
          @EventDatePicker="clearDatepickerFn"
          ref="comForm"
          @EventReset="resetFn"
          @EventOnsubmit="queryFn"
          :list="comForm"
        >
        </comForm>
      </div>

      <ComTable
        @handleSizeChange="changePageSizeFn"
        @handleCurrentChange="CurrentChangeFn"
        :key="romdom"
        v-loading="loading"
        :list="tableList"
        :modes="tableModes"
        :config="{ border: true }"
        :pagination="{
          total: paging.total,
          pageNum: paging.pageNum,
        }"
      >
        <!-- idStr: row.idStr,
                    docIdStr: row.docIdStr,
                    docId: row.docId,
                    docType: docType, -->
        <el-table-column align="left" width="100" #default="{ row }">
          <template v-if="row.status == 1">
            <el-button
              size="mini"
              plain
              type="primary"
              @click="
                $router.push({
                  path: '/contentSupervision/AuditManagement/contentReview',
                  query: {
                    id: row.docIdStr,
                    type: row.docType,
                    verifyId: row.idStr,
                    docId: row.docIdStr,
                  },
                })
              "
              v-hasPermi="['base:verifyOpinion:getInfo']"
            >
              审核
            </el-button>
          </template>
          <template v-else>
            <el-button
              @click="GoTodetailFn(row)"
              size="mini"
              plain
              type="primary"
              v-hasPermi="['work:verifyOpinion:getByVerify']"
            >
              查看
            </el-button>
          </template>
        </el-table-column>
      </ComTable>
    </div>
  </div>
</template>

<script>
import ComForm from "../../../components/comForm.vue";
import ComSelect from "../../../components/comSelect.vue";
import ComTable from "../../../components/comTable.vue";
import comForm from "../../../components/comForm.vue";
import { getListDataApi } from "@/wss/api/label";
import { getContentReviewApi } from "@/wss/api/ContentReview";
import { getDocGetInfoApi } from "@/wss/api/ContentSupervision/ContentManagement";

// import { getDocGetInfoApi } from "@/wss/api/ContentSupervision";

export default {
  components: { ComSelect, ComForm, comForm, ComTable },

  data() {
    return {
      // 加载状态
      loading: false,
      paging: {
        pageNum: 1,
        pageSize: 10,
        total: 10,
        status: "",
        temp: "",
      },
      // 修复切换”审核不会更新bug“
      romdom: "",
      currentSelect: "ToBeReviewed",
      currentShowText: {
        first: "查看",
        second: "删除",
      },
      options: {
        value: "",
        title: "快速筛选",
        list: [
          {
            value: "",
            label: "全部",
          },
          {
            label: "审核中",
            value: "1",
          },
          {
            label: "审核成功",
            value: "3",
          },
          {
            label: "审核失败",
            value: "2",
          },
        ],
      },
      // 动态生成下拉列表的筛选条件
      dynamicFilter: {},
      // 表格的数据
      tableList: [],
      tableModes: [
        {
          type: "selection",
        },

        {
          label: "内容编号",
          mode: "docNo",
        },
        {
          label: "内容",
          mode: "title",
          showOverflowTooltip: true,
        },
        {
          label: "内容类型",
          mode: "docType",
        },
        {
          label: "内容标签",
          mode: "label",
          showOverflowTooltip: true,
        },

        {
          label: "提交人",
          mode: "createdBy",
        },
        {
          label: "审核人",
          mode: "updatedBy",
        },
        {
          label: "状态",
          mode: "status",
          isSwitch: false,
          width: 100,
          align: "center",
          isShowTag: true,
          options: [
            {
              l: "审核中",
              v: 1,
              type: "只要让它匹配不上就是蓝色",
            },
            {
              l: "已驳回",
              v: 2,
              type: "danger",
            },
            {
              l: "通过",
              v: 3,
            },
          ],
        },
        {
          label: "提交审核日期",
          showOverflowTooltip: true,
          mode: "createdTime",
        },
      ],
      // form组件的数据
      comForm: {
        modes: [
          {
            placeholder: "请输入内容编号",
            formType: "input",
            label: "内容编号",
            value: "",
            mode: "docNo",
          },
          {
            placeholder: "请输入内容标题",
            formType: "input",
            label: "内容",
            value: "",
            mode: "title",
          },
          {
            placeholder: "请输入筛选条件",
            formType: "select",
            label: "内容类型",
            value: "",
            mode: "docType",
            select: [],
          },
          {
            placeholder: "请输入筛选条件",
            formType: "select",
            mode: "labelId",
            label: "内容标签",
            value: "",
            select: [],
          },
          {
            placeholder: "请输入提交人姓名",
            formType: "input",
            label: "提交人",
            value: "",
            mode: "createdBy",
          },
          {
            placeholder: "请输入审核人姓名",
            formType: "input",
            label: "审核人",
            value: "",
            mode: "updatedBy",
          },
          {
            mode: "temp",
            formType: "datePicker",
            label: "提交日期",
            value: "",
            pickerType: "daterange",
            startPlaceholder: "开始日期",
            endPlaceholder: "结束日期",
          },
        ],
      },
    };
  },
  mounted() {
    this.getContentReviewFn();
    this.getLabelFn();
  },
  methods: {
    async getLabelFn() {
      let { rows } = await getListDataApi();
      this.comForm.modes.forEach((item) => {
        if (item.mode === "labelId") {
          item.select = rows.map((item) => {
            return { label: item.content, value: item.idStr };
          });
        }
      });
    },
    clearDatepickerFn() {
      this.paging.temp = "";
      this.paging.beginTime = null;
      this.paging.endTime = null;
    },
    // 查看审核成功和审核详细的结果
    async GoTodetailFn(row) {
      console.log(row);

      let { data } = await getDocGetInfoApi({ id: row.docIdStr });
      console.log(data, "data---------------------------------");
      const docType = row.docType;
      if (row.status === "2") {
        if (docType === "问答") {
          this.$router.push({
            path: "/contentPlatform/askAnswer/askAnswer-failReason",
            query: { id: data.esId, verifyId: row.idStr, docId: row.docIdStr },
          });
        } else if (
          docType === "法条" ||
          docType === "法规" ||
          docType === "行政法规"
        ) {
          this.$router.push({
            path: "/contentPlatform/laws/laws-failReason",
            query: { id: data.esId, verifyId: row.idStr, docId: row.docIdStr },
          });
        } else if (docType === "政策" || docType === "文章") {
          this.$router.push({
            path: "/contentPlatform/article/article-failReason",
            query: { id: data.esId, verifyId: row.idStr, docId: row.docIdStr },
          });
        } else if (docType === "头条") {
          this.$router.push({
            path: "/contentPlatform/headline/headline-failReason",
            query: { id: data.esId, verifyId: row.idStr, docId: row.docIdStr },
          });
        }
        return;
      }

      if (docType === "问答") {
        this.$router.push({
          path: "/contentPlatform/askAnswer/askAnswer-details",
          query: { esId: data.esId },
        });
      } else if (docType === "法条" || docType === "法规") {
        this.$router.push({
          path: "/contentPlatform/laws/laws-details",
          query: { esId: data.esId },
        });
      } else if (docType === "政策" || docType === "文章") {
        this.$router.push({
          path: "/contentPlatform/article/article-details",
          query: { esId: data.esId },
        });
      } else if (docType === "头条") {
        this.$router.push({
          path: "/contentPlatform/headline/headline-details",
          query: { esId: data.esId },
        });
      }
    },
    // 数据转换成对象

    // 页容量发生改变
    changePageSizeFn(value) {
      this.paging.pageNum = 1;
      this.paging.pageSize = value;
      this.getContentReviewFn();
    },
    // 重设函数
    resetFn() {
      this.currentSelect = "";
      this.romdom = Math.random();
      this.options.value = "";
      this.paging.status = "";
    },
    // 当前页发生改变时候
    CurrentChangeFn(pageNum) {
      console.log(pageNum);
      this.paging.pageNum = pageNum;
      this.getContentReviewFn();
    },
    // 查询
    queryFn(arr) {
      // 改成后端需要的字段

      arr.forEach((item) => {
        for (const key in item) {
          this.paging[key] = item[key];
        }
      });
      let temp = this.paging["temp"];

      if (this.paging["temp"] instanceof Array) {
        this.paging.pageNum = 1;
        if (
          this.tableModes[this.tableModes.length - 1].mode === "createdTime"
        ) {
          this.paging.rejectBeginTime = null;
          this.paging.rejectEndTime = null;
          this.paging.beginTime = temp[0].split(" ")[0];
          this.paging.endTime = temp[1].split(" ")[0];
        } else {
          this.paging.beginTime = null;
          this.paging.endTime = null;
          this.paging.rejectBeginTime = temp[0].split(" ")[0];
          this.paging.rejectEndTime = temp[1].split(" ")[0];
        }

        this.paging.temp = "";
      }
      console.log(this.paging, "筛选数据");
      this.paging.status = this.options.value;
      this.getContentReviewFn();
    },
    // 获取列表数据
    async getContentReviewFn() {
      this.loading = true;
      let result = await getContentReviewApi(this.paging);
      console.log(result, "内容管理返回的数据111111");
      if (result.code === 200) {
        this.paging.total = result.total;
        this.tableList = result.rows;

        this.tableList.forEach((item) => {
          // 是否有这个属性
          this.dynamicFilter.label ? "" : (this.dynamicFilter.label = []);
          this.dynamicFilter.docType ? "" : (this.dynamicFilter.docType = []);

          if (!this.dynamicFilter.docType.includes(item.docType)) {
            this.dynamicFilter.docType.push(item.docType);
          }
        });
        // 动态生成筛选下拉列表
        this.comForm.modes.forEach((item) => {
          switch (item.mode) {
            case "docType":
              item.select = this.arrTransformObj(this.dynamicFilter.docType);
              break;
            default:
              break;
          }
        });
      }

      this.loading = false;
    },

    GotoDetailFn() {
      this.$router.push({
        path: "/contentPlatform/askAnswer/askAnswer-details",
      });
    },
    changeFn(value) {
      this.$refs.comForm.resetFn();
      this.options.value = value;
      this.paging = {
        pageNum: 1,
        pageSize: 10,
        status: "",
        total: 10,
      };
      this.paging.status = value;
      console.log(value);
      this.getContentReviewFn();
      if (value !== "1" && value !== "") {
        this.comForm.modes[0].label = "任务编号";
        this.comForm.modes[6].label = "驳回时间";
        this.tableModes[this.tableModes.length - 1].mode = "updatedTime";
        this.tableModes[this.tableModes.length - 1].label = "驳回时间";
      } else {
        this.comForm.modes[0].label = "内容编号";
        this.comForm.modes[6].label = "提交时间";
        this.tableModes[this.tableModes.length - 1].mode = "createdTime";
        this.tableModes[this.tableModes.length - 1].label = "提交时间";
      }
    },
  },
};
</script>

<style lang ="scss" scoped>
</style>